import com.demo.Student;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;


@WebServlet(name = "SecondServlet", value = "/SecondServlet")
public class SecondServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public SecondServlet() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        ServletContext context = this.getServletContext();
        Student student = (Student) context.getAttribute("stu");
        PrintWriter out = response.getWriter();
        String title = "学生信息";
        String docType = "<!DOCTYPE html> \n";
        String msg = "5s后返回输入页面";
        out.println("<html>\n" + "<head><script language=javascript>    function my-fun() 　　{ 　　 \n" +
                "        alert(\"" + msg + "\"); 　　\n" +
                "    } 　　\n" +
                "    window.onload = my-fun;</script>");
        out.println(docType + "<title>" + title + "</title>" + "</head>\n" + "<body bgcolor=\"#f0f0f0\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" + "  <li><b>学号</b>：" + student.getSno() + "\n" + "  <li><b>姓名</b>：" + student.getName() + "\n" + "</ul>\n" + "</body></html>");
        response.setHeader("Refresh", "5;url=input.html");
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}

